package zhishu.iceyyy.com.kd_khd.db;

import android.content.Context;

import com.j256.ormlite.dao.Dao;

import java.util.List;

import zhishu.iceyyy.com.kd_khd.bean.db_bean.Life_UserInfo;


/**
 * Created by luoliwen on 16/4/28.
 * 完成对数据库的CRUD的操作
 */
public class Z_UserInfoDao {
    private Context context;
    private Dao<Life_UserInfo, Integer> userDao;
    private Z_DataBaseHelper helper;

    public Z_UserInfoDao(Context context) {
        this.context = context;
        helper = Z_DataBaseHelper.getInstance(context);
        try {
            userDao = helper.getDao(Life_UserInfo.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void addUser(int id, long CrTime, long LastTime, String LoginName, int Type, int Status,
                        String NetworkNames, String NetworkId) {
        try {
            Life_UserInfo user = new Life_UserInfo();
            user.setId(String.valueOf(id));
            user.setCrTime(CrTime);
            user.setLastTime(LastTime);
            user.setLoginName(LoginName);
            user.setType(Type);
            user.setStatus(Status);
            user.setNetworkName(NetworkNames);
            user.setNetworkId(NetworkId);
            userDao.create(user);

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    String XTWUserInfos;

    public String query() {
        try {
            XTWUserInfos = userDao.queryForAll().get(0).getLoginName();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return XTWUserInfos;
    }

    Life_UserInfo XTWUserInfoss;

    public Life_UserInfo query2() {
        try {
            XTWUserInfoss = userDao.queryForAll().get(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return XTWUserInfoss;
    }

    public void deleteUser(Life_UserInfo user) {
        try {
            userDao.delete(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
